package com.woniuxy.oa.dao;

import com.woniuxy.oa.dao.provider.SalaryProvider;
import com.woniuxy.oa.entity.Salary;
import com.woniuxy.oa.entity.query.SalaryQuery;
import org.apache.ibatis.annotations.*;

import java.util.List;


/**
 * The interface Salary dao.
 *
 * @Auther: 毓
 * @Date: 2019 /12/25 11:19
 * @Description:薪资DAO
 */
public interface SalaryDAO {
    /**
     * Add.
     *
     * @param salary the salary
     */
    @Insert("insert into oa_salary values (#{id},#{employee.id},#{basePay},#{bonus},#{royalty},#{taxes},#{insure},#{loan})")
    void add(Salary salary);

    /**
     * Update.
     * 修改工资
     *
     * @param salary tv he salary
     */
    @Update("update oa_salary set basePay=#{basePay},bonus=#{bonus},royalty=#{royalty},taxes=#{taxes},insure=#{insure},loan=#{loan} where id=#{id} ")
    void update(Salary salary);

    /**
     * Gets by user id.
     * 查询自己的薪资
     *
     * @param userId the user id
     * @return the by user id
     */
    @Select("select * from oa_salary where userId=#{user.userId}")
    Salary getByEmployeeId(String userId);


    /**
     * Gets by user name.
     * 根据员工姓名等条件模糊查询其工资
     *
     * @param
     * @return
     */
    @SelectProvider(type = SalaryProvider.class, method = "select")
    List<Salary> getByQuery(@Param("salary") SalaryQuery salary);

    @Select("select s.*,u.empno empNo,u.level empLevel,u.name empName,u.gender empGender,d.deptname deptName,d.id deptId from oa_salary s ,oa_emp u left join oa_dept d on d.id=u.deptid where u.id=s.employeeid  and s.id=#{id} ")
    @Results({
            @Result(id = true, column = "id", property = "id"),
            @Result(column = "deptName", property = "deptName"),
            @Result(column = "empName", property = "empName"),
            @Result(column = "empGender", property = "empGender"),
            @Result(column = "deptId", property = "deptId"),
    })
    Salary getById(String id);
}